package com.aishua.fire.common.openid;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class OpenIdUtils {
	
	public static String getOpenId(HttpServletRequest request){
		//获取用户授权OPENID
		
        String urlNameString = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx19900063c5ea347b&secret=90d176770180b617553e98826224d05c&code="+request.getParameter("code")+"&grant_type=authorization_code";
		String openIdJson = HttpClintUtils.sendGet(urlNameString);
		log.info("**********************获取用户OPENID="+openIdJson);
		JSONObject jsStr = JSONObject.parseObject(openIdJson);
   
		log.info((String) jsStr.get("openid"));
		
		return (String) jsStr.get("openid");
		
		
	}
	
	public static String getOpenIdByCode(String code){
		//获取用户授权OPENID
		
        String urlNameString = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx19900063c5ea347b&secret=90d176770180b617553e98826224d05c&code="+code+"&grant_type=authorization_code";
		String openIdJson = HttpClintUtils.sendGet(urlNameString);
		log.info("**********************获取用户OPENID="+openIdJson);
		JSONObject jsStr = JSONObject.parseObject(openIdJson);
   
		log.info((String) jsStr.get("openid"));
		
		return (String) jsStr.get("openid");
	}
}
